package main

import (
	"fmt"

	"log"

	"gitee.com/eeppee_admin/go-ecs/src/dbg"
	"gitee.com/eeppee_admin/go-ecs/src/ecscore"
)

/// I dont know how this works

func main() {
	storage := ecscore.NewEntitySimpleStorage()
	executor := ecscore.NewSequentialSystemExecutor()

	sim := ecscore.NewSimulation(storage, executor)

	for {
		sim.Update()
		sim.Render()

		// add an entity, returning its id
		id := sim.AddEntity(&Position{
			X: 15.0,
			Y: 15.0,
		}, &Health{
			Current: 5,
			Total:   5,
		})
		// the most efficient way to randomly query data for entities is via an EntityView
		// view := ecscore.newen[PositionAndHealth](sim)

		// data is of type PositionAndHealth
		// data := view.Get(id)

		// components can be removed
		sim.RemoveComponent(id, Health{})

		// or added
		// sim.AddComponent(id, &SomeOtherComponent{})

		// and entities can be deleted
		sim.DeleteEntity(id)

		var query = ecscore.NewQuery[struct {
			Id ecscore.EntityId
			*Health
			// *Animation
		}]()

		// execute an iterate over all matching entities
		result := query.Execute(sim)
		for result.Next() {
			// log.Printf("Health: %v / Animation: %v", result.Item.Health, result.Item.Animation)
		}

		// turn into a list of results
		result = query.Execute(sim)
		resultList := result.ToList()
		log.Printf("%+v", resultList)

		// simframe := ecscore.NewSimpleSimulation()
		// 	simframe.Frame = &ecscore.SimulationFrame{}
		// 	debugger.Render(simframe.Frame)
		break
	}

	debugger := dbg.NewEcsDebugSystem()
	fmt.Printf("%+v", debugger)
}

type Position struct {
	X float32
	Y float32
}

type Health struct {
	Current int
	Total   int
}

type PositionAndHealth struct {
	Position *Position
	Health   *Health
}
